<html>
<head> 
	<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-mobile/1.4.5/jquery.mobile.min.css">
    <script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery-mobile/1.4.5/jquery.mobile.min.js"></script>
    <script src="https://cdn.bootcss.com/require.js/2.3.6/require.min.js"></script>

    <title>GB/T 32224 热量表</title> 

<script>
var NORMAL_FLOW={
	15: 1.5,
	20: 2.5,
	25: 3.5,
	32: 6,
	40: 10,
	50: 15,
	65: 25,
	80: 40,
	100: 60,
	125: 100,
	150: 150,
	200: 250,
	250: 400,
	300: 600,
	400: 1000
}

function toRound(value){
	var value2;
	if (value > 1000){
		value2 = value.toFixed(0);
	}
	else if (value > 100){
		value2 = value.toFixed(1);
	}
	else if (value > 10){
		value2 = value.toFixed(2);
	}
	else if (value > 1){
		value2 = value.toFixed(3);
	}
	else{
		value2 = value.toFixed(4);
	}

	if (value < 1000){
		toString(value2);

		while (value2.charAt(value2.length - 1) == 0){
			value2 = value2.substr(0, value2.length - 1);

			if (value2.charAt(value2.length - 1) == '.'){
				value2 = value2.substr(0, value2.length - 1);
				break;
			}
		}
	}
	return value2
}

function calcEq(qp, q, accuracy){
	if (accuracy == 1 && qp < 100){
		throw '1级表常用流量需大于100m<sup>3</sup>/h(DN125及以上)\n';
	}

	if (accuracy == 1){
		eq = 1 + 0.01 * qp / q;
	}
	else if (accuracy == 2){
		eq = 2 + 0.02 * qp / q;
	}
	else if (accuracy == 3){
		eq = 3 + 0.05 * qp / q;
	}
	else{
		throw '准确度等级异常：' + accuracy;
	}
	if (eq > 5){
		eq = 5;
	}
	return eq
}


// 计算标准参数
function calcPara(){
	// 获取口径
	var size = $('[name="size"]:checked').val();
	// message += '<li data-icon="false">口径：\t' + size + '</li>\n';

	// 量程比获取
	var ratio = $('[name="ratio"]:checked').val();
	// message += '<li data-icon="false">量程比：\t' + ratio + '</li>\n';

	// 获取准确度等级
	var accuracy = $('[name="accuracy"]:checked').val();
	// message += '<li data-icon="false">准确度等级：\t' + accuracy + '</li>\n';
	// message += '<br>'

	// 计算
	var aera = 3.1415926 * (size / 1000 / 2) * (size / 1000 / 2)  // 截面积

	var flow_qp = NORMAL_FLOW[size]  // 常用流量
	var flow_qs = flow_qp * 2  // 最大流量
	var flow_qi = flow_qp / ratio  // 最大流量

	var message = '<h2>计算结果</h2>\n'
	message += '<ul data-role="listview" data-inset="true" id="result">\n';

	try{
		var flow_qt1 = flow_qi  // 测试点1
		var eq1 = calcEq(flow_qp, flow_qt1, accuracy)
		var flow_qt2 = flow_qp * 0.1  // 测试点2
		var eq2 = calcEq(flow_qp, flow_qt2, accuracy)
		var flow_qt3 = flow_qp  // 测试点3
		var eq3 = calcEq(flow_qp, flow_qt3, accuracy)
		message += '<li data-icon="false">常用流量(q<sub>p</sub>)：\t' + flow_qp + 'm<sup>3</sup>/h, ' + toRound(flow_qp / 3600 / aera) + 'm/s' + '</li>\n';
		message += '<li data-icon="false">常小流量(q<sub>i</sub>)：\t' + toRound(flow_qi) + 'm<sup>3</sup>/h, ' + toRound(flow_qi / 3600 / aera) + 'm/s' + '</li>\n';
		message += '<li data-icon="false">流量上限(q<sub>s</sub>)：\t' + toRound(flow_qs) + 'm<sup>3</sup>/h, ' + toRound(flow_qs / 3600 / aera) + 'm/s' + '</li>\n';
		message += '<br>'
		message += '<li data-icon="false">测试点1(q<sub>i</sub> ~ 1.1q<sub>i</sub>)：\n\n\t' + toRound(flow_qt1) + 'm<sup>3</sup>/h, ' + toRound(flow_qt1 / 3600 / aera) + 'm/s, ±' + eq1 + '%</li>\n';
		message += '<li data-icon="false">测试点2(0.1q<sub>p</sub> ~ 0.11q<sub>p</sub>)：\t' + toRound(flow_qt2) + 'm<sup>3</sup>/h, ' + toRound(flow_qt2 / 3600 / aera) + 'm/s, ±' + eq2 + '%</li>\n';
		message += '<li data-icon="false">测试点3(0.9q<sub>p</sub> ~ 1.0q<sub>p</sub>)：\t' + toRound(flow_qt3) + 'm<sup>3</sup>/h, ' + toRound(flow_qt3 / 3600 / aera) + 'm/s, ±' + eq3 + '%</li>\n';
	}
		catch(err){
		message += '<li data-icon="false">'+ err + '</li>\n';
	}

    message += '</ul>\n';
	// 输出信息
    document.getElementById("message").innerHTML=message;
    // $( "#result" ).listview("refresh");
}
</script>

</head>
<body>
    <div data-role="page" id="pageone">
		<div data-role="header" data-position="fixed">
			<h1 id="header-device-detail">GB/T 32224 热量表</h1>
			<a href="javascript:document.location='./flow.html'" class="ui-btn ui-btn-right ui-alt-icon ui-nodisc-icon ui-corner-all ui-btn-icon-notext ui-icon-back"></a>
		</div>
		<div data-role="main" class="ui-content">
		<form action="">
			<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
				<legend>口径：</legend>
				<label for="size_15">DN15</label>
				<input type="radio" name="size" id="size_15" onchange="calcPara()" value="15">
				<label for="size_20">DN20</label>
				<input type="radio" name="size" id="size_20" onchange="calcPara()" value="20">
				<label for="size_25">DN25</label>
				<input type="radio" name="size" id="size_25" onchange="calcPara()" value="25">
				<label for="size_32">DN32</label>
				<input type="radio" name="size" id="size_32" onchange="calcPara()" value="32">
				<label for="size_40">DN40</label>
				<input type="radio" name="size" id="size_40" onchange="calcPara()" value="40">
				<label for="size_50">DN50</label>
				<input type="radio" name="size" id="size_50" onchange="calcPara()" value="50" checked >
				<label for="size_65">DN65</label>
				<input type="radio" name="size" id="size_65" onchange="calcPara()" value="65">
				<label for="size_80">DN80</label>
				<input type="radio" name="size" id="size_80" onchange="calcPara()" value="80">
				<label for="size_100">DN100</label>
				<input type="radio" name="size" id="size_100" onchange="calcPara()" value="100">
				<label for="size_125">DN125</label>
				<input type="radio" name="size" id="size_125" onchange="calcPara()" value="125">
				<label for="size_150">DN150</label>
				<input type="radio" name="size" id="size_150" onchange="calcPara()" value="150">
				<label for="size_200">DN200</label>
				<input type="radio" name="size" id="size_200" onchange="calcPara()" value="200">
				<label for="size_250">DN250</label>
				<input type="radio" name="size" id="size_250" onchange="calcPara()" value="250">
				<label for="size_300">DN300</label>
				<input type="radio" name="size" id="size_300" onchange="calcPara()" value="300">
				<label for="size_400">DN400</label>
				<input type="radio" name="size" id="size_400" onchange="calcPara()" value="400">
			</fieldset>
			
			<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
				<legend>量程比：</legend>
				<label for="radio_25">25:1</label>
				<input type="radio" name="ratio" id="radio_25" onchange="calcPara()" value="25">
				<label for="radio_50">50:1</label>
				<input type="radio" name="ratio" id="radio_50" onchange="calcPara()" value="50" checked >
				<label for="radio_100">100:1</label>
				<input type="radio" name="ratio" id="radio_100" onchange="calcPara()" value="100">
				<label for="radio_250">250:1</label>
				<input type="radio" name="ratio" id="radio_250" onchange="calcPara()" value="250">
			</fieldset>
			
			<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
				<legend>准确度:</legend>
				<label for="accuracy_1">1级</label>
			    <input type="radio" name="accuracy" id="accuracy_1" onchange="calcPara()" value="1">
				<label for="accuracy_2">2级</label>
				<input type="radio" name="accuracy" id="accuracy_2" onchange="calcPara()" value="2" checked >	
				<label for="accuracy_3">3级</label>
				<input type="radio" name="accuracy" id="accuracy_3" onchange="calcPara()" value="3">	
			</fieldset>

		</form>
		<li data-role="fieldcontain">
			<div id="message">
				<p>依据标准：</p>
				<p>* 《GB/T 32224-2020 热能表》</p>
				<p>* 《JJG 225-2001 热能表检定规程》</p>
				<br>
				<p>点击参数开始计算</p>
			</div>
		</li>

	</div>

</body>
</html>